const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const cors = require('./cors');
const { apiLogger } = require('./apiLogger');


const app = express();
// 用于请求静态资源
const staticRoot = path.resolve(__dirname, "../public");
app.use("/static", express.static(staticRoot));

// 用于获取post请求的消息体
app.use(express.urlencoded({ extended: true }));

// 用于解析application/json格式的请求体
app.use(express.json());

// 用cors解决跨域
app.use(cors);

// 使用cookie-parser中间件,会在req对象中注入cookies属性
app.use(cookieParser());

// 记录api的日志记录
app.use(apiLogger);

// 应用token中间件
app.use(require("./tokenVerification"));


// api路由
app.use("/api/user", require('./api/user'));
app.use("/api/userinfo", require('./api/userinfo'));
app.use("/api/taskList", require('./api/taskList'));
app.use("/api/folder", require('./api/folder'));
app.use("/api/files", require('./api/files'));

app.use("/api/adminUser", require('./api/adminUser'));
app.use("/api/manage", require('./api/background-task'));
app.use("/api/workbench", require('./api/backstage-folder'));
app.use("/api/manageFiles", require('./api/backstage-file'));


let port = 9000;
app.listen(port, () => {
    console.log('服务运行成功 9000');
})

